package dp;

public class ds718 {
    public static void main(String[] args) {
        System.out.println(findLength(new int[]{0,1,1,1,1}, new int[]{1,0,1,0,1}));
    }
    public static int findLength(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        int re = 0;
        int[][] dp = new int[m][n];
        for (int i = 0; i < m; i++) {
            if(nums1[i] == nums2[0])
                dp[i][0] = 1;
            re = Math.max(re, dp[i][0]);
        }
        for (int i = 0; i < n; i++) {
            if(nums1[0] == nums2[i])
                dp[0][i] = 1;
            re = Math.max(re, dp[0][i]);
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if(nums1[i] == nums2[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                re = Math.max(re, dp[i][j]);
            }
        }
        return re;
    }
}
